//回文数
//121反转121返回true 123反转321返回false
let x = 12221;
// let xString = String(x)
// console.log(xString)
// let xArr = xString.split('')
// console.log(xArr,xArr.length)
// let halfL = parseInt(xArr.length/2)
// console.log(halfL)
// console.log(xString.substr(0,halfL))
// if(xArr.length%2==0){
//     console.log(xString.substr(halfL,xArr.length+1))
// }else{
//     console.log(xString.substr(halfL+1,xArr.length+1))
// }

function back(x) {
    if(x<0||(x%10==0&&x!=0))return false;
    let xArr = String(x).split('');
    let xLen = xArr.length;
    let halfL = parseInt(xLen/2);
    let left = String(x).substr(0,halfL)
    let right
    if(xLen%2==0){
        right = String(x).substr(halfL,xArr.length+1).split('').reverse().join('')
    }else{
        right= String(x).substr(halfL+1,xArr.length+1).split('').reverse().join('')
    }
    console.log(right==left,'?')

}
console.time('01')
back(x)
console.timeEnd('01')

var isPalindrome = function(x) {
    if(x<0||(x%10==0&&x!=0))return false;
    let x1 = String(x)
    let arr = x1.split('')
    if (arr.reverse().join('') == x1) return true
    return false
};

console.log(isPalindrome(x))